package com.cyjt.operation.fragment;

import java.util.ArrayList;
import java.util.List;

import com.cyjt.operation.R;
import com.cyjt.operation.adapter.WorkOrderManagementAdapter;
import com.cyjt.operation.bean.WorkOrder;
import com.cyjt.operation.ui.WorkOrderDetails;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;

/**
 * 已完成工单的Fragment，被嵌入工单管理的ViewPager
 * 
 * @author LTP
 *
 */
public class WorkOrderManagementFinishedFragment extends Fragment implements
		OnItemClickListener {
	private View view;
	private ListView listView_workorder_management_finished;
	private List<WorkOrder> workOrderList = new ArrayList<WorkOrder>();
	private WorkOrderManagementAdapter mWorkOrderManagementAdapter;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		initWorkOrder();// 测试用
		Log.d("LTP", "onCreate");
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		Log.d("LTP", "onCreateView");
		// TODO Auto-generated method stub
		view = inflater.inflate(
				R.layout.fragment_workorder_management_finished, container,
				false);
		initView();
		return view;
	}

	/**
	 * 控件初始化
	 */
	private void initView() {
		// TODO Auto-generated method stub
		listView_workorder_management_finished = (ListView) view
				.findViewById(R.id.listView_workorder_management_finished);
		mWorkOrderManagementAdapter = new WorkOrderManagementAdapter(
				getActivity(), R.layout.list_view_item_workorder_management,
				workOrderList);
		listView_workorder_management_finished
				.setAdapter(mWorkOrderManagementAdapter);
		listView_workorder_management_finished.setOnItemClickListener(this);
	}

	/**
	 * 测试用
	 */
	private void initWorkOrder() {
		WorkOrder workOrder1 = new WorkOrder(1, "环湖东路部署", "2015-07-09", "重启基站");
		workOrderList.add(workOrder1);
		WorkOrder workOrder2 = new WorkOrder(2, "环湖东路部署", "2015-07-10", "重启基站");
		workOrderList.add(workOrder2);
		WorkOrder workOrder3 = new WorkOrder(3, "环湖东路部署", "2015-07-11", "重启基站");
		workOrderList.add(workOrder3);
		WorkOrder workOrder4 = new WorkOrder(4, "环湖东路部署", "2015-07-12", "重启基站");
		workOrderList.add(workOrder4);
		WorkOrder workOrder5 = new WorkOrder(5, "环湖东路部署", "2015-07-13", "重启基站");
		workOrderList.add(workOrder5);
		WorkOrder workOrder6 = new WorkOrder(6, "环湖东路部署", "2015-07-14", "重启基站");
		workOrderList.add(workOrder6);
	}

	@Override
	public void onItemClick(AdapterView<?> parent, View view, int position,
			long id) {
		// TODO ListView的点击事件
		WorkOrder workOrder = workOrderList.get(position);
		Intent intent = new Intent(getActivity(), WorkOrderDetails.class);
		intent.putExtra("workOrder", workOrder);
		startActivity(intent);
	}

}
